home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / gfx / misc / MesaGL-tk.lha / src / awindow.c next >
C/C++ Source or Header  |  1998-09-21  |  29KB  |  969 lines

  1. /*
  2.  * $Id: Awindow.c 3.00 1998/09/21 19:17:47 NielsF Exp NielsF $
  3.  */
  4. /*
  5.  * (c) Copyright 1993, Silicon Graphics, Inc.
  6.  * ALL RIGHTS RESERVED
  7.  * Permission to use, copy, modify, and distribute this software for
  8.  * any purpose and without fee is hereby granted, provided that the above
  9.  * copyright notice appear in all copies and that both the copyright notice
  10.  * and this permission notice appear in supporting documentation, and that
  11.  * the name of Silicon Graphics, Inc. not be used in advertising
  12.  * or publicity pertaining to distribution of the software without specific,
  13.  * written prior permission.
  14.  *
  15.  * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  16.  * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  17.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  18.  * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
  19.  * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  20.  * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  21.  * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  22.  * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  23.  * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
  24.  * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  25.  * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  26.  * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  27.  *
  28.  * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  29.  */
  30.  
  31. /*
  32.  * $Log: Awindow.c $
  33.  * Revision 3.0  1998/09/21  19:17:47  NielsF
  34.  * bumped to mesa 3.0
  35.  * 
  36.  * $Log: Awindow.c $
  37.  * Revision 1.8  1997/06/25  19:17:47  StefanZ
  38.  * bumped to mesa 2.2
  39.  * 
  40.  * Revision 1.5  1996/10/07  00:18:11  StefanZ
  41.  * Mesa 2.0 Fixed
  42.  * 
  43.  * Revision 1.4  1996/08/14  22:53:16  StefanZ
  44.  * rev 1.3 tk fixes was from George 'Wulf' Krämer
  45.  * 
  46.  * Revision 1.3  1996/08/14  22:23:31  StefanZ
  47.  * Modified due to api change in amigaMesa
  48.  * Implemented div. Input modifier and changed windowhandling
  49.  * 
  50.  * Revision 1.2  1996/06/02  00:03:03  StefanZ
  51.  * Started to use RCS to keep track of code.
  52.  * 
  53.  */
  54. /*
  55.  * History:
  56.  * 
  57.  * 1.0 960315 Now almost evetything is implemented
  58.  * 1.1 960425 Fixed problem with double closeclicks (Thanx to Daniel Jönsson)
  59.  * 1.2 960731 Modified due to api change in amigaMesa
  60.  * 1.3 Implemented div. Input modifier and changed windowhandling (Georg 'Wulf' Krämer)
  61.  * 
  62.  * TODO:
  63.  * Exposefunc
  64.  * 
  65.  * 
  66.  */
  67.  
  68. //#define USE_CLIP_LAYER
  69. #undef USE_CLIP_LAYER
  70.  
  71. #include <stdio.h>
  72. #include <stdlib.h>
  73. #include <string.h>
  74. #include <signal.h>
  75.  
  76. #include <intuition/intuition.h>
  77. #include <devices/inputevent.h>
  78. #include <inline/exec.h>
  79. #include <inline/intuition.h>
  80. #include <inline/graphics.h>
  81.  
  82. #ifdef USE_CLIP_LAYER
  83. #include <inline/layers.h>
  84. #endif
  85. extern struct ExecBase *SysBase;
  86.  
  87. #include <gl/gltk.h>
  88. #include <gl/amigamesa.h>
  89.  
  90. #define static
  91.  
  92. #if defined(__cplusplus) || defined(c_plusplus)
  93. #define class c_class
  94. #endif
  95.  
  96. #if DBG
  97. #define TKASSERT(x)                                     \
  98. if ( !(x) ) {                                           \
  99.     PrintMessage("%s(%d) Assertion failed %s\n",        \
  100.         __FILE__, __LINE__, #x);                        \
  101. }
  102. #else
  103. #define TKASSERT(x)
  104. #endif                                           /*
  105.                                             * * DBG 
  106.                                             */
  107.  
  108. /*
  109.  * Some Bitmasks for amigaevents 
  110.  */
  111. #define ControlMask         (IEQUALIFIER_CONTROL)
  112. #define ShiftMask           (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT)
  113. #define MousePressedMask    (SELECTDOWN | MENUDOWN | MIDDLEDOWN)
  114.  
  115. /**********************************************************************/
  116.  
  117. struct wnd {
  118.   int x, y, width, height;
  119.   GLenum type, dmPolicy;
  120.   GLint ID;
  121.  
  122.   struct amigamesa_context *context;
  123.   struct Screen *screen;
  124.   struct Window *window;
  125. #ifdef USE_CLIP_LAYER
  126.   struct Region *clipreg;
  127. #endif
  128. };
  129.  
  130. struct wnd win =
  131. {0, 0, 100, 100, TK_INDEX, 0, 0, NULL, NULL, NULL
  132. #ifdef USE_CLIP_LAYER
  133. ,NULL
  134. #endif
  135. };
  136.  
  137. /*
  138.  * Local prototypes 
  139.  */
  140. struct Region *clipWindow(struct Window *win,
  141.               LONG minX, LONG minY, LONG maxX, LONG maxY);
  142. struct Region *clipWindowToBorders(struct Window *win);
  143.  
  144. GLboolean tkPopupEnable = TRUE;
  145.  
  146. /*
  147.  * Fixed palette support.  
  148.  */
  149. // #define BLACK   PALETTERGB(0,0,0)
  150. // #define WHITE   PALETTERGB(255,255,255)
  151. // #define NUM_STATIC_COLORS   (COLOR_BTNHIGHLIGHT - COLOR_SCROLLBAR + 1)
  152. static void (*ExposeFunc) (int, int) = NULL;
  153. static void (*ReshapeFunc) (GLsizei, GLsizei) = NULL;
  154. static void (*DisplayFunc) (void) = NULL;
  155. static GLenum(*KeyDownFunc) (int, GLenum) = NULL;
  156. static GLenum(*MouseDownFunc) (int, int, GLenum) = NULL;
  157. static GLenum(*MouseUpFunc) (int, int, GLenum) = NULL;
  158. static GLenum(*MouseMoveFunc) (int, int, GLenum) = NULL;
  159. static void (*IdleFunc) (void) = NULL;
  160.  
  161. #ifdef USE_CLIP_LAYER
  162. /*
  163.  * Get from clipping example of the RKM 
  164.  */
  165. /*
  166.  * clipWindow()
  167.  * Clip a window to a specified rectangle (given by upper left and
  168.  * lower right corner.)  the removed region is returned so that it
  169.  * may be re-installed later.
  170.  */
  171. struct Region *clipWindow(struct Window *win,
  172.               LONG minX, LONG minY, LONG maxX, LONG maxY)
  173. {
  174.   struct Region *new_region;
  175.   struct Rectangle my_rectangle;
  176.  
  177.   /*
  178.    * set up the limits for the clip 
  179.    */
  180.   my_rectangle.MinX = minX;
  181.   my_rectangle.MinY = minY;
  182.   my_rectangle.MaxX = maxX;
  183.   my_rectangle.MaxY = maxY;
  184.  
  185.   /*
  186.    * get a new region and OR in the limits. 
  187.    */
  188.   if (NULL != (new_region = NewRegion())) {
  189.     if (FALSE == OrRectRegion(new_region, &my_rectangle)) {
  190.       DisposeRegion(new_region);
  191.       new_region = NULL;
  192.     }
  193.   }
  194.  
  195.   /*
  196.    * Install the new region, and return any existing region.
  197.    * If the above allocation and region processing failed, then
  198.    * new_region will be NULL and no clip region will be installed.
  199.    */
  200.   return (InstallClipRegion(win->WLayer, new_region));
  201. }
  202.  
  203. /*
  204.  * clipWindowToBorders()
  205.  * clip a window to its borders.
  206.  * The removed region is returned so that it may be re-installed later.
  207.  */
  208. struct Region *clipWindowToBorders(struct Window *win)
  209. {
  210.   return (clipWindow(win, win->BorderLeft, win->BorderTop,
  211.      win->Width - win->BorderRight - 1, win->Height - win->BorderBottom - 1));
  212. }
  213. #endif
  214.  
  215. float colorMaps[] = {
  216.     0.000000, 1.000000, 0.000000, 1.000000, 0.000000, 1.000000, 
  217.     0.000000, 1.000000, 0.333333, 0.776471, 0.443137, 0.556863, 
  218.     0.443137, 0.556863, 0.219608, 0.666667, 0.666667, 0.333333, 
  219.     0.666667, 0.333333, 0.666667, 0.333333, 0.666667, 0.333333, 
  220.     0.666667, 0.333333, 0.666667, 0.333333, 0.666667, 0.333333, 
  221.     0.666667, 0.333333, 0.039216, 0.078431, 0.117647, 0.156863, 
  222.     0.200000, 0.239216, 0.278431, 0.317647, 0.356863, 0.400000, 
  223.     0.439216, 0.478431, 0.517647, 0.556863, 0.600000, 0.639216, 
  224.     0.678431, 0.717647, 0.756863, 0.800000, 0.839216, 0.878431, 
  225.     0.917647, 0.956863, 0.000000, 0.000000, 0.000000, 0.000000, 
  226.     0.000000, 0.000000, 0.000000, 0.000000, 0.247059, 0.247059, 
  227.     0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 
  228.     0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 
  229.     0.498039, 0.498039, 0.749020, 0.749020, 0.749020, 0.749020, 
  230.     0.749020, 0.749020, 0.749020, 0.749020, 1.000000, 1.000000, 
  231.     1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 
  232.     0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 
  233.     0.000000, 0.000000, 0.247059, 0.247059, 0.247059, 0.247059, 
  234.     0.247059, 0.247059, 0.247059, 0.247059, 0.498039, 0.498039, 
  235.     0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 
  236.     0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 
  237.     0.749020, 0.749020, 1.000000, 1.000000, 1.000000, 1.000000, 
  238.     1.000000, 1.000000, 1.000000, 1.000000, 0.000000, 0.000000, 
  239.     0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 
  240.     0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 
  241.     0.247059, 0.247059, 0.498039, 0.498039, 0.498039, 0.498039, 
  242.     0.498039, 0.498039, 0.498039, 0.498039, 0.749020, 0.749020, 
  243.     0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 
  244.     1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 
  245.     1.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 
  246.     0.000000, 0.000000, 0.000000, 0.000000, 0.247059, 0.247059, 
  247.     0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059